package it.tukano.swingdeco.menubar;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JCheckBoxMenuItem;

public class BoxItem extends JCheckBoxMenuItem {

    /* default serial version uid*/
    private static final long serialVersionUID = 0;

    public BoxItem(String label) {
        super(label);
    }

    public BoxItem onSelect(final Runnable r) {
        addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                if(isSelected()) r.run();
            }
        });
        return this;
    }

    public BoxItem onDeselect(final Runnable r) {
        addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                if(!isSelected()) r.run();
            }
        });
        return this;
    }
}
